package cn.hycat;

/**
 * @author lzhycat
 * @date 2022-09-07 01:23
 */
import java.util.Scanner;

public class Main {
    static class Node{
        int val;
        Node next;
        public Node(int val) {
            this.val = val;
        }
        public Node(int val, Node next) {
            this.val = val;
            this.next = next;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        Node pre = new Node(-1);
        for(int i = 0; i < (n - 1) * 2; i++) {
            int one = sc.nextInt();
            int two = sc.nextInt();
            runTwo(pre, two, h);
            runOne(pre, one, two);
        }
        int d = sc.nextInt();
        delete(pre, d);
    }

    private static void delete(Node pre, int d) {
        Node cur = pre;
        while (cur.next != null) {
            if(cur.next.val == d && cur.next.next == null) {
               cur.next = null;
               break;
            } else if(cur.next.val == d && cur.next.next != null) {
                cur.next = cur.next.next;
                break;
            }
            cur = cur.next;
        }
    }

    private static void runOne(Node pre, int one, int two) {
        Node cur = pre;
        while (cur != null) {
            if(cur.val == two) {
                Node oneNode = new Node(one);
                oneNode.next = cur.next;
                cur.next = oneNode;
            }
            cur = cur.next;
        }
    }
    
    public static void runTwo(Node pre, int two, int h) {
        boolean flag = false;
        Node cur = pre;
        if(two == h) {
            return;
        }
        while (cur != null) {
            if(cur.val == two) {
                flag = true;
                break;
            }
            cur = cur.next;
        }
        if(!flag) {
            cur.next = new Node(two);
        }
    }
}